window.onload = function () {
    var candlestickData = [];
    var MA5Data = [];
    var MA10Data = [];
    var MA20Data = [];
    var barData = [];
    var theDate = []
    var colorsData = [];
    for (var i = 0; i < marketDailyData.length; i++) {
        var obj = marketDailyData[i];
        if (obj.openingPrice > obj.closingPrice) {
            colorsData.push("blue");
        } else {
            colorsData.push("red");
        }
        candlestickData.push([obj.lowestPrice, obj.openingPrice, obj.closingPrice, obj.highestPrice]);
        theDate.push(obj.theDate);
        MA5Data.push(obj.closeprice5);
        MA10Data.push(obj.closeprice10);
        MA20Data.push(obj.closeprice20);
        barData.push(obj.turnoverVol);
    }

    var param = {
        "id": "chart",
        "boundary": true,
        "lineColor":"blue",
        "lineWidth":0.5,
        "font":"10px sans-serif",
        "fontColor":"red",
        "fractionalDigits":3,
        "margin": {"top": 10, "bottom": 20, "left": 10, "right": 10},
        "grid": [
            {"ratio": 0.7, "scale": true, "middle": 0},
            {"ratio": 0.3, "scale": false, "middle": 0}
        ],
        "axisText":{
            "data":theDate,
            "filter":function(i,v){
                return i % 15 == 0;
            }
        },
        "series": [
            {
                "name": "日K",
                "gridIndex": 0,
                "type": "candlestick",
                "colors": ["red", "#0000ff"],
                "data": candlestickData
            },
            {
                "name": "MA5",
                "gridIndex": 0,
                "type": "line",
                "color": "yellow",
                "data": MA5Data
            },
            {
                "name": "MA10",
                "gridIndex": 0,
                "type": "line",
                "color": "pink",
                "data": MA10Data
            },
            {
                "name": "MA10",
                "gridIndex": 0,
                "type": "line",
                "color": "brown",
                "data": MA20Data
            },
            {
                "name": "成交量",
                "gridIndex": 1,
                "type": "bar",
                "colors": colorsData,
                "data": barData
            }
        ]
    };
    initChart(param);
};
